//
//  OldGoldDetailViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 15/10/7.
//  Copyright (c) 2015年 RuiBen. All rights reserved.
//

#import "OldGoldDetailViewController.h"
#import "OrderDetailViewController.h"
#import "OldCutDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "oldDetailTableViewCell.h"
#import "DepositDetailViewController.h"
#import "CancelOrderOrDepositViewController.h"

@interface OldGoldDetailViewController ()<OrderDetailDelegate,DepositDetailDelegate,CancelOrderOrDepositDelegate>
{
    OrderDetailViewController *orderDetailVC;
    DepositDetailViewController *depositDetailVC;
    CancelOrderOrDepositViewController *cancelOrderVC;
    //cut
    NSMutableArray *cutUrlArray;
    NSMutableArray *cutItemCodeArray;
    NSMutableArray *cutItemNameArray;
    NSMutableArray *cutWeightArray;
    NSMutableArray *cutGramArray;
    NSMutableArray *cutStatusArray;
    //old
    NSMutableArray *oldWeightArray;
    
    NSMutableArray *oldRecyclePriceArray;
    NSMutableArray *oldLossArray;
     NSMutableArray *oldRealPriceArray;
    NSMutableArray *oldAmountArray;
     NSMutableArray *oldStatusArray;
    NSMutableArray *oldLineIdArray;
   
    
}
@end

@implementation OldGoldDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (orderDetailVC.view!=nil) {
        
        [orderDetailVC removeFromParentViewController];
        [orderDetailVC.view removeFromSuperview];
        
    }
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }

    

    cutUrlArray=[NSMutableArray array];
    cutItemCodeArray=[NSMutableArray array];
    cutItemNameArray=[NSMutableArray array];
    cutWeightArray=[NSMutableArray array];
    cutGramArray=[NSMutableArray array];
    cutStatusArray=[NSMutableArray array];
   
    
    oldWeightArray=[NSMutableArray array];
    oldRecyclePriceArray=[NSMutableArray array];
    oldLossArray=[NSMutableArray array];
    oldRealPriceArray=[NSMutableArray array];
    oldAmountArray=[NSMutableArray array];
    oldStatusArray=[NSMutableArray array];
    oldLineIdArray=[NSMutableArray array];
       // Do any additional setup after loading the view from its nib.
    [_alphaView setBackgroundColor:[Global parseColor:WESTORE_TRANSCLUCENT]];
    [_alphaView addTarget:self action:@selector(alphaViewClick) forControlEvents:UIControlEventTouchUpInside];
     [_orderBtn addTarget:self action:@selector(orderBtnClick) forControlEvents:UIControlEventTouchUpInside];
     [self requestOrderDetail:_docNumStr];
}
-(void)requestOrderDetail:(NSString *)codeStr
{
    if ([Global getLoginToken].length>0) {
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        NSMutableDictionary *params=[[NSMutableDictionary alloc] init];
        [params setObject:[Global getLoginToken] forKey:@"Token"];
        [params setObject:codeStr forKey:@"DocNum"];
        // NSLog(@"paramsLIST====%@",params);
        [HttpRequest requestData:@"StoreManager/GetOldMaterialDetail" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            // NSLog(@"detaillll=%@",severDataDict.dataDict);
            if (isSuccess) {
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    [Global hideProgressHUDInternal:self.view];
                    _numlabel.text=[severDataDict.dataDict objectForKey:@"DocNum"];
                   // [self resizeLabel:_numlabel];
                    [Global resizeForLable:_numlabel WithText:_numlabel.text parentView:self.view];
                    NSString *statusStr=[severDataDict.dataDict objectForKey:@"DocStatus"];
                    _statuslabel.text=[NSString stringWithFormat:@"【%@】",statusStr];
                    if ([statusStr isEqualToString:@"未上交"]) {
                        [_statuslabel setTextColor:[Global parseStatusColor:statusStr]];
                        _cancelOldBtn.hidden=NO;
                    }
                    else if ([statusStr isEqualToString:@"已上交"])
                    {
                       _cancelOldBtn.hidden=YES;
                        [_statuslabel setTextColor:[Global parseStatusColor:statusStr]];
                        
                    }

                    else //if ([statusStr isEqualToString:@"已收定金"])
                    {
                        _cancelOldBtn.hidden=YES;
                        [_statuslabel setTextColor:[Global parseStatusColor:statusStr]];
                        
                        
                    }
                    
                    //[self resizeLabel:_statuslabel];
                    
                    
                    CGRect statusframe=_statuslabel.frame;
                    statusframe.origin.x=_numlabel.frame.origin.x+_numlabel.frame.size.width;
                    _statuslabel.frame=statusframe;
                    
                    
                    if ([[severDataDict.dataDict objectForKey:@"MemberName"] length]!=0) {
                        _memberNamelabel.text=[severDataDict.dataDict objectForKey:@"MemberName"];
                    }
                    else
                    {
                        _memberNamelabel.text=@"未填写";
                    }
                    if ([severDataDict.dataDict objectForKey:@"GuideName"]!=[NSNull null]) {
                        _guideNamelabel.text=[severDataDict.dataDict objectForKey:@"GuideName"];
                    }
                   // [self resizeLabel:_memberNamelabel];
                   // [self resizeLabel:_guideNamelabel];
                    [Global resizeForLable:_memberNamelabel WithText:_memberNamelabel.text parentView:self.view];
                    [Global resizeForLable:_guideNamelabel WithText:_guideNamelabel.text parentView:self.view];
                    
                    CGRect frame=_guideNameTaglabel.frame;
                    frame.origin.x=_memberNamelabel.frame.origin.x+_memberNamelabel.frame.size.width+12;
                    _guideNameTaglabel.frame=frame;
                    
                    CGRect frame1=_guideNamelabel.frame;
                    frame1.origin.x=_guideNameTaglabel.frame.origin.x+_guideNameTaglabel.frame.size.width+3;
                    _guideNamelabel.frame=frame1;
                    
                    CGRect frame2=_storeNameTaglabel.frame;
                    frame2.origin.x=_guideNamelabel.frame.origin.x+_guideNamelabel.frame.size.width+12;
                    _storeNameTaglabel.frame=frame2;
                    
                    CGRect frame3=_storeNamelabel.frame;
                    frame3.origin.x=_storeNameTaglabel.frame.origin.x+_storeNameTaglabel.frame.size.width+3;
                    _storeNamelabel.frame=frame3;
                    
                    
                    
                    if ([severDataDict.dataDict objectForKey:@"StoreName"]!=[NSNull null]) {
                        _storeNamelabel.text=[severDataDict.dataDict objectForKey:@"StoreName"];
                    }
                    if ([severDataDict.dataDict objectForKey:@"DocDate"]!=[NSNull null]) {
                        _datelabel.text=[severDataDict.dataDict objectForKey:@"DocDate"];
                    }
                    
                    if ([severDataDict.dataDict objectForKey:@"WhsName"]!=[NSNull null]) {
                        _submitTolabel.text=[severDataDict.dataDict objectForKey:@"WhsName"];
                    }
                   //       if ([severDataDict.dataDict objectForKey:@"Remark"]!=[NSNull null]) {
//                        _remarkTextView.text=[severDataDict.dataDict objectForKey:@"Remark"];
//                      //  NSLog(@"_remarkTextView.text===%@",_remarkTextView.text);
//                        
//                       // [Global resizeTextView:_remarkTextView contentStr:_remarkTextView.text];
//                        CGFloat height=  [Global heightForTextView:_remarkTextView WithText:_remarkTextView.text];
//                        
//                        CGRect frameA=_remarkTextView.frame;
//                        frameA.size.height=height;
//                        _remarkTextView.frame=frameA;
//
//                        
//                        CGRect frameD=_remarkView.frame;
//                        frameD.size.height=_remarkTextView.frame.origin.y+_remarkTextView.frame.size.height+10;
//                        _remarkView.frame=frameD;
//
//                    }
//
                    //orderInfo
                    NSString *dateStr=[severDataDict.dataDict objectForKey:@"OrderDate"];
                    _ordeDatelabel.text=dateStr;
                    
                   // [self resizeLabel:_ordeDatelabel];
                    [Global resizeForLable:_ordeDatelabel WithText:_ordeDatelabel.text parentView:self.view];
                    if (dateStr.length>0) {
                        CGRect framea=_ordeNumTaglabel.frame;
                        framea.origin.x=_ordeDatelabel.frame.origin.x+_ordeDatelabel.frame.size.width+12;
                        _ordeNumTaglabel.frame=framea;
                        
                        
                        
                    }
                    else
                    {
                        CGRect framea=_ordeNumTaglabel.frame;
                        framea.origin.x=_ordeDatelabel.frame.origin.x+_ordeDatelabel.frame.size.width;
                        _ordeNumTaglabel.frame=framea;
                        
                    }
                    CGRect frameb=_ordeNumlabel.frame;
                    frameb.origin.x=_ordeNumTaglabel.frame.origin.x+_ordeNumTaglabel.frame.size.width+2;
                    _ordeNumlabel.frame=frameb;
                    
                    NSString *numStr=[severDataDict.dataDict objectForKey:@"OrderNum"] ;
                    if (numStr.length>0) {
                        _orderNotelabel.hidden=YES;
                    }
                    else
                    {
                        _orderNotelabel.hidden=NO;
                    }
                    _ordeNumlabel.text=numStr;
                  //  [self resizeLabel:_ordeNumlabel];
                     [Global resizeForLable:_ordeNumlabel WithText:_ordeNumlabel.text parentView:self.view];
                    
                    NSString *totalStr=[NSString stringWithFormat:@"¥%0.02f",[[severDataDict.dataDict objectForKey:@"OrderDocTotal"] floatValue]];
                    _goodTotallabel.text=totalStr;
                    // [self resizeLabel:_goodTotallabel];
                     [Global resizeForLable:_goodTotallabel WithText:_goodTotallabel.text parentView:self.view];
                    
                    CGRect frame4=_goodTotalTaglabel.frame;
                    frame4.origin.x=_ordeNumlabel.frame.origin.x+_ordeNumlabel.frame.size.width+12;
                    _goodTotalTaglabel.frame=frame4;
                    
                    CGRect frame5=_goodTotallabel.frame;
                    frame5.origin.x=_goodTotalTaglabel.frame.origin.x+_goodTotalTaglabel.frame.size.width+3;
                    _goodTotallabel.frame=frame5;
                    
                
                    NSString *decutibleStr=[NSString stringWithFormat:@"¥%0.02f",[[severDataDict.dataDict objectForKey:@"Deduction"] floatValue]];
                    _decutiblelabel.text=decutibleStr;
                 //   [self resizeLabel:_decutiblelabel];
                      [Global resizeForLable:_decutiblelabel WithText:_decutiblelabel.text parentView:self.view];
                    
                    CGRect frame8=_decutibleTaglabel.frame;
                    frame8.origin.x=_goodTotallabel.frame.origin.x+_goodTotallabel.frame.size.width+12;
                    _decutibleTaglabel.frame=frame8;
                    
                    CGRect frame9=_decutiblelabel.frame;
                    frame9.origin.x=_decutibleTaglabel.frame.origin.x+_decutibleTaglabel.frame.size.width+3;
                    _decutiblelabel.frame=frame9;
                    
                    NSMutableArray *mDataLineArray=[severDataDict.dataDict objectForKey:@"DataLine2"];
                   
                    for (int i=0; i<mDataLineArray.count; i++) {
                        [cutItemCodeArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"CutItemCode"]];
                        [cutItemNameArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"CutItemName"]];
                        [cutStatusArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"LineStatus"]];
                        [cutGramArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"CutGram"]];
                        if ([[mDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]!=[NSNull  null]&&[[[mDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"] length]>0) {
                            [cutUrlArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"ImageUrl"]];
                        }
                        else
                        {
                            [cutUrlArray addObject:@""];
                        }
                        
                        [cutWeightArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"CutItemGram"]];
                       
                        //[orderDetailAttributeArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                    }
                    _cutInfolabel.text=[NSString stringWithFormat:@"(共%d件，剪金%0.02fg)",[[severDataDict.dataDict objectForKey:@"Number2"] integerValue],[[severDataDict.dataDict objectForKey:@"Gram2"] floatValue]];
                    
                      _oldInfolabel.text=[NSString stringWithFormat:@"(共%d件，旧料%0.02fg)",[[severDataDict.dataDict objectForKey:@"Number"] integerValue],[[severDataDict.dataDict objectForKey:@"Gram"] floatValue]];

                    [_cutTableView reloadData];
                    CGRect frameD=_cutTableView.frame;
                    frameD.size.height=120*mDataLineArray.count;
                    _cutTableView.frame=frameD;
//                    //
                    if (mDataLineArray.count==0) {
                        _cutInfoView.hidden=YES;
                        CGRect frameL=_oldInfoView.frame;
                        frameL.origin.y=_cutInfoView.frame.origin.y;
                        _oldInfoView.frame=frameL;
                    }
                    else
                    {
                        _cutInfoView.hidden=NO;
                        CGRect frameL=_oldInfoView.frame;
                        frameL.origin.y=_cutTableView.frame.origin.y+_cutTableView.frame.size.height;
                        _oldInfoView.frame=frameL;
                    }
                   
                    
                    NSMutableArray *mDataLine2Array=[severDataDict.dataDict objectForKey:@"DataLine1"];
                    
                    for (int i=0; i<mDataLine2Array.count; i++) {
                        [oldWeightArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"Gram"]];
                        [oldRecyclePriceArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"GoldPrice"]];
                        [oldAmountArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"LineTotal"]];
                        [oldLossArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"LossRate"]];
                        [oldRealPriceArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"DealLineTotal"]];
                        [oldLineIdArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"LineId"]];
                        
                        [oldStatusArray addObject:[[mDataLine2Array objectAtIndex:i] objectForKey:@"LineStatus"]];
                        //[orderDetailAttributeArray addObject:[[mDataLineArray objectAtIndex:i] objectForKey:@"Attributes"]];
                    }
                    
                    [_oldTableView reloadData];
                    
                    
                    CGRect framee=_oldTableView.frame;
                    framee.size.height=60*mDataLine2Array.count;
                    framee.origin.y=_oldInfoView.frame.origin.y+_oldInfoView.frame.size.height;

                    _oldTableView.frame=framee;
                    
                    if (mDataLine2Array.count==0) {
                        _oldInfoView.hidden=YES;
                        
                        CGRect framef=_remarkView.frame;
                        framef.origin.y=_cutTableView.frame.origin.y+_cutTableView.frame.size.height+15;
                        _remarkView.frame=framef;
                    }
                    else
                    {
                        _oldInfoView.hidden=NO;
                        
                        CGRect framef=_remarkView.frame;
                        framef.origin.y=_oldTableView.frame.origin.y+_oldTableView.frame.size.height+15;
                        _remarkView.frame=framef;

                    }
                    //                    //
                  
//                    //
                    [_scrollView setContentSize:CGSizeMake(0, _remarkView.frame.origin.y+ _remarkView.frame.size.height)];
                    [_scrollView setScrollEnabled:YES];
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    //  [Global showTextHud:requestResultStr view:self.view];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    [Global loginViewController:self noteStr:requestResultStr];
                        //    [Global loginViewController:self];
                    }
                    
                }
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:@"连接失败" view:self.view];
            }
        }];
        
    }
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView==_cutTableView) {
        return cutItemCodeArray.count;
    }
    else  {
        return oldLineIdArray.count;
    }
        
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     if (tableView==_cutTableView) {
    return 120;
     }
     else{
         return 60;
     }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_cutTableView) {
        
    static NSString * const  OldCutDetailIdentifier = @"OldCutDetailIdentifier";
    OldCutDetailTableViewCell *cell=( OldCutDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: OldCutDetailIdentifier];
    if (cell==nil) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"OldCutDetailTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //        cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame] ;
    //        cell.selectedBackgroundView.backgroundColor = [UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f];
    if (cutItemCodeArray.count>0) {
        cell.nameLabel.text=[NSString stringWithFormat:@"%@ %@",[cutItemCodeArray objectAtIndex:indexPath.row],[cutItemNameArray objectAtIndex:indexPath.row]];
    }
    NSString *weightStr=@"";
    NSString *cutWeightStr=@"";
    if (cutWeightArray.count>0) {
        weightStr=[NSString stringWithFormat:@"%0.02fg",[[cutWeightArray objectAtIndex:indexPath.row] floatValue]];
    }
    if (cutGramArray.count>0) {
        cutWeightStr=[NSString stringWithFormat:@"%0.02fg",[[cutGramArray objectAtIndex:indexPath.row] floatValue]];
    }
    cell.detailLabel.text=[NSString stringWithFormat:@"克重%@   剪金%@",weightStr,cutWeightStr];
    if (cutUrlArray.count>0) {
        if ([[cutUrlArray objectAtIndex:indexPath.row] length]>0) {
            
            [cell.productImage setImageWithURL:[NSURL URLWithString:[cutUrlArray objectAtIndex:indexPath.row]]];
        }
        else
        {
            [cell.productImage setImage:[UIImage imageNamed:@"zhanweitu_.png"]];
        }
    }
    if (cutStatusArray.count>0) {
        if ([[cutStatusArray objectAtIndex:indexPath.row]isEqualToString:@"N"]) {
            cell.statusLabel.text=@"未上交";
            [cell.statusLabel setTextColor:[Global parseStatusColor:cell.statusLabel.text]];
            }
            else
            {
               cell.statusLabel.text=@"已上交";
                
                [cell.statusLabel setTextColor:[Global parseStatusColor:cell.statusLabel.text]];
                
            }

        }
        cell.dotLineLabel.hidden=NO;
        cell.lineLabel.hidden=YES;
        if (indexPath.row==cutStatusArray.count-1) {
            cell.dotLineLabel.hidden=YES;
            cell.lineLabel.hidden=NO;

        }
    
     return cell;
    }
    
    else
    {
        
        static NSString * const  oldDetailIdentifier = @"oldDetailIdentifier";
        oldDetailTableViewCell *cell=( oldDetailTableViewCell *)[tableView dequeueReusableCellWithIdentifier: oldDetailIdentifier];
        if (cell==nil) {
            NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"oldDetailTableViewCell" owner:self options:nil];
            cell = [array objectAtIndex:0];
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSString *weightStr=@"";
        NSString *recycleStr=@"";
        NSString *lossStr=@"";
         NSString *amountStr=@"";
        NSString *realPriceStr=@"";
        if (oldWeightArray.count>0) {
            weightStr=[NSString stringWithFormat:@"%0.02fg",[[oldWeightArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (oldRecyclePriceArray.count>0) {
            recycleStr=[NSString stringWithFormat:@"%0.02f",[[oldRecyclePriceArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (oldLossArray.count>0) {
            lossStr=[NSString stringWithFormat:@"%0.02f%%",[[oldLossArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (oldAmountArray.count>0) {
            amountStr=[NSString stringWithFormat:@"¥%0.02f",[[oldAmountArray objectAtIndex:indexPath.row] floatValue]];
        }
        if (oldRealPriceArray.count>0) {
            realPriceStr=[NSString stringWithFormat:@"¥%0.02f",[[oldRealPriceArray objectAtIndex:indexPath.row] floatValue]];
        }


        cell.detailLabel.text=[NSString stringWithFormat:@"足金%@  回收金价%@  损耗%@  金额%@  实收%@" ,weightStr,recycleStr,lossStr,amountStr,realPriceStr];
        if (oldStatusArray.count>0) {
            if ([[oldStatusArray objectAtIndex:indexPath.row]isEqualToString:@"N"]) {
                cell.statusLabel.text=@"未上交";
                [cell.statusLabel setTextColor:[Global parseStatusColor:cell.statusLabel.text]];
            }
            else
            {
                cell.statusLabel.text=@"已上交";
                
                [ cell.statusLabel setTextColor:[Global parseStatusColor:cell.statusLabel.text]];
                
            }

        //cell.statusLabel.text=[oldStatusArray objectAtIndex:indexPath.row];
        }
        return cell;

    }
    
}

-(void)alphaViewClick
{
    if (self.view!=nil) {
        [self.view removeFromSuperview];
        [self removeFromParentViewController];
        
    }

}
-(void)orderBtnClick
{
    if (_ordeNumlabel.text.length>0) {
        
        if (depositDetailVC.view!=nil) {
            
            [depositDetailVC removeFromParentViewController];
            [depositDetailVC.view removeFromSuperview];
            
        }

    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
    orderDetailVC=[[OrderDetailViewController alloc] init];
    orderDetailVC.delegate=self;
    orderDetailVC.docNumStr=_ordeNumlabel.text;
    orderDetailVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:orderDetailVC];
    [self.view addSubview:orderDetailVC.view];
    }
    else
    {
        UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"没有关联订单" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
        [alert show];
    }
    
    

}
//orderDetailDelegate
-(void)RelateDepositBtnClick
{
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }

    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    depositDetailVC=[[DepositDetailViewController alloc] init];
    depositDetailVC.delegate=self;
    depositDetailVC.docNumStr=orderDetailVC.relatedDocNumLabel.text;
    depositDetailVC.view.frame = CGRectMake(0,
                                            0,
                                            self.view.bounds.size.width,
                                            self.view.bounds.size.height);
    
    [self addChildViewController:depositDetailVC];
    [self.view addSubview:depositDetailVC.view];
    
}
-(void)CancelOrderBtnClick
{
    //    if (orderDetailVC.view!=nil) {
    //      //  NSLog(@"rrwrwrwrwrw");
    //        [orderDetailVC removeFromParentViewController];
    //        [orderDetailVC.view removeFromSuperview];
    //
    //    }
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=orderDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Order";
    cancelOrderVC.titleStr=@"取消订单";
    
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
    // [self.view bringSubviewToFront:cancelOrderVC.view];
    
}
//DepositDetailDelegate
-(void)DepositDetailCanCelDepositClick
{
    if (cancelOrderVC.view!=nil) {
        
        [cancelOrderVC removeFromParentViewController];
        [cancelOrderVC.view removeFromSuperview];
        
    }
    cancelOrderVC=[[CancelOrderOrDepositViewController alloc] init];
    cancelOrderVC.delegate=self;
    cancelOrderVC.DocNumStr=depositDetailVC.detailNumLabel.text;
    cancelOrderVC.DocTypeStr=@"Deposit";
    cancelOrderVC.titleStr=@"取消定金单";
    cancelOrderVC.view.frame = CGRectMake(0,
                                          0,
                                          self.view.bounds.size.width,
                                          self.view.bounds.size.height);
    
    [self addChildViewController:cancelOrderVC];
    [self.view addSubview:cancelOrderVC.view];
    
}
- (IBAction)cancelOldClick:(id)sender {
    if ([self.delegate respondsToSelector:@selector(CancelOldBtnClick)]) {
        [self.delegate CancelOldBtnClick];
    }

}
-(void)DepositDetailRelateOrderClick
{
    if (depositDetailVC.view!=nil) {
        
        [depositDetailVC removeFromParentViewController];
        [depositDetailVC.view removeFromSuperview];
        
    }
    if (orderDetailVC.view!=nil) {
        [orderDetailVC.view removeFromSuperview];
        [orderDetailVC removeFromParentViewController];
        
    }
//    orderDetailVC=[[OrderDetailViewController alloc] init];
//    orderDetailVC.delegate=self;
//    orderDetailVC.docNumStr=[orderNumArray objectAtIndex:orderListCellTag];
//    orderDetailVC.view.frame = CGRectMake(0,
//                                          0,
//                                          self.view.bounds.size.width,
//                                          self.view.bounds.size.height);
//    
//    [self addChildViewController:orderDetailVC];
//    [self.view addSubview:orderDetailVC.view];
    
    
    
    
}

@end
